<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>设置管理员ip</title>
    <script src="../static/jquery-3.2.1.min.js"></script>
    <script src="../static/bootstrap.min.js"></script>
    <script type="text/javascript">
        document.write('<link rel="stylesheet" href="../static/login.css?v=' + Math.random() + '">');
    </script>
</head>
<body style="margin: 0px">
<div class="cover"></div>
<div id="login_frame">

    <div id="image_logo">Admin Set And Save</div>
    <form method="post" action="login.js" id="myform">
        <div id="password" class="clear">
            <label class="label_input">口令</label>
            <input type="password" id="pwd1" class="text_field"/>
        </div>
        <div id="password" class="clear">
            <label class="label_input">IP</label>
            <input type="text" id="pwd2" class="text_field"/>
        </div>
        <div class="forget_pwd">
            <a id="test">验证口令</a>
            <a id="save1" style="display: none">特殊</a>
        </div>
    </form>
</div>
</body>
<script>
    flag = true
    $("#save1").click(function () {
        var pwd = $("#pwd1").val()
        var ip = $("#pwd2").val()
        save = {'pwd': pwd, 'ip': ip}
        $.post('/save1', save, function (data) {
            alert(data)
        })
    })
    $("#test").click(function () {
        kouling = $("#pwd1").val()
        dic = {'kouling': kouling}
        $.post('/get_admin', dic, function (data) {
            console.log(data);
            if (data == '口令不正确') {
                $("#pwd2").val(data)
                var childs = $(".forget_pwd").children()
                if (childs.length == 3) {
                    $(".forget_pwd").children('#save').remove()
                }
            } else {
                $("#pwd2").val(data)
                var childs = $(".forget_pwd").children()
                console.log(childs);
                if (childs.length == 2) {
                    $(".forget_pwd").append('<a id="save">保存</a>')
                }
            }
        })
    })
    {#    为动态生成的子元素添加点击事件#}
    $(".forget_pwd").on('click','#save',function () {
        var pwd = $("#pwd1").val()
        var ip = $("#pwd2").val()
        save = {'pwd': pwd, 'ip': ip}
        $.post('/save', save, function (data) {
            alert(data)
        })
    })


</script>


</html>